const app = getApp()
Page({
  data: {
    showbar:false,
    loading: true,
    page: 0,
    special: [],
    shop: []
  },
  param:{
    id:0
  },
  //监听页面加载
  onLoad: function(options) {
    app.getParam(options,(param) => {
      this.param.id = param.id
      app.isLbs(rel => {
        if(rel){
          this.getitem();
        }
      })
    })
  },
  //上拉加载
  onReachBottom: function() {
    this.setData({
      loading: true,
    });
    this.getitem();
  },
  //点击请求数据
  getitem: function () {
    if (this.data.loading) {
      var param = {
        id: this.param.id,
        citycode:app.globalData.location.adcode,
        page: this.data.page + 1
      }
      app.api().Get('api/v1/ais/shop/lists',param,(result)=>{
        if (result.code == 200) {
          var shop = this.data.shop;
      
          shop = shop.concat(result.data.shop)  
          // for (let i in result.data.shop) {
          //   shop.push(result.data.shop[i]);
          // }
          this.setData({
            shop: shop,
            page: param.page,
          });
          if (param.page == 1){
            this.setData({
              special: result.data.special
            });
          }
        }
        this.setData({
          loading: false,
        });
      })
    }
  },
  //分享按钮
  onShareAppMessage: function () {
    var special = this.data.special;
    return {
      title: special.content,
      imageUrl: special.picture,
      path: '/packageIndex/pages/shop/index?ucode=' + app.globalData.loginuser.ucode + '&id=' + this.data.special.id
    }
  },

  //滚动
  onPageScroll(res) {
    let scrollTop = res.scrollTop;
    this.setData({
      showbar:120 <= scrollTop ? true : false
    })
    wx.setNavigationBarColor({
      frontColor:120 <= scrollTop ? '#000000' :'#ffffff',
      backgroundColor: '#ffffff'
    })
  }
})